/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.adv.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.adv.entity.HkEnterpriseHotAdv;
import com.thinkgem.jeesite.modules.hk.adv.service.HkEnterpriseHotAdvService;

/**
 * 企业广告热度广告Controller
 * @author 罗天文
 * @version 2018-04-04
 */
@Controller
@RequestMapping(value = "${adminPath}/adv/hkEnterpriseHotAdv")
public class HkEnterpriseHotAdvController extends BaseController {

	@Autowired
	private HkEnterpriseHotAdvService hkEnterpriseHotAdvService;
	
	@ModelAttribute
	public HkEnterpriseHotAdv get(@RequestParam(required=false) String id) {
		HkEnterpriseHotAdv entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkEnterpriseHotAdvService.get(id);
		}
		if (entity == null){
			entity = new HkEnterpriseHotAdv();
		}
		return entity;
	}
	
	@RequiresPermissions("adv:hkEnterpriseHotAdv:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkEnterpriseHotAdv hkEnterpriseHotAdv, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkEnterpriseHotAdv> page = hkEnterpriseHotAdvService.findPage(new Page<HkEnterpriseHotAdv>(request, response), hkEnterpriseHotAdv); 
		model.addAttribute("page", page);
		return "hk/adv/hkEnterpriseHotAdvList";
	}

	@RequiresPermissions("adv:hkEnterpriseHotAdv:view")
	@RequestMapping(value = "form")
	public String form(HkEnterpriseHotAdv hkEnterpriseHotAdv, Model model) {
		model.addAttribute("hkEnterpriseHotAdv", hkEnterpriseHotAdv);
		return "hk/adv/hkEnterpriseHotAdvForm";
	}

	@RequiresPermissions("adv:hkEnterpriseHotAdv:edit")
	@RequestMapping(value = "save")
	public String save(HkEnterpriseHotAdv hkEnterpriseHotAdv, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkEnterpriseHotAdv)){
			return form(hkEnterpriseHotAdv, model);
		}
		hkEnterpriseHotAdvService.save(hkEnterpriseHotAdv);
		addMessage(redirectAttributes, "保存企业广告热度广告成功");
		return "redirect:"+Global.getAdminPath()+"/adv/hkEnterpriseHotAdv/?repage";
	}
	
	@RequiresPermissions("adv:hkEnterpriseHotAdv:edit")
	@RequestMapping(value = "delete")
	public String delete(HkEnterpriseHotAdv hkEnterpriseHotAdv, RedirectAttributes redirectAttributes) {
		hkEnterpriseHotAdvService.delete(hkEnterpriseHotAdv);
		addMessage(redirectAttributes, "删除企业广告热度广告成功");
		return "redirect:"+Global.getAdminPath()+"/adv/hkEnterpriseHotAdv/?repage";
	}

}